package com.sjh.commons.base.result;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 功能描述
 *
 * @author songjiahao
 * @date 2023/03/10  19:18
 */
@Data
@Accessors(chain = true)
public class R<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;
    public static <S> R succ(Codes codes,S data){
        return new R().setCode(codes.getCode())
                .setMsg(codes.getMsg())
                .setData(data);
    }
    public static R succ(){
        return new R().setCode(Codes.SUCC.getCode())
                .setMsg(Codes.SUCC.getMsg());
    }
    public static R error(Codes codes){
        return error(codes,null);
    }
    public static <S> R error(Codes codes,S data){
        return new R()
                .setCode(codes.getCode())
                .setMsg(codes.getMsg())
                .setData(data);
    }
}
